package com.xiaomazi.order.controller;

import com.xiaomazi.common.utils.JwtUtils;
import com.xiaomazi.common.utils.R;
import com.xiaomazi.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: llxy-parent
 * @description: 订单服务
 * @author: 小马子
 * @create: 2023-03-04 17:19
 **/
@RestController
@RequestMapping("/eduorder")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/createOrder/{courseId}")
    public R createOrder(@PathVariable String courseId,
                         HttpServletRequest request){
        return orderService.createOrder(courseId, JwtUtils.getMemberIdByJwtToken(request));
    }


    @GetMapping("/getOrderByOrderId/{orderId}")
    public R getOrderByOrderId(@PathVariable String orderId){
        return orderService.getOrderByOrderId(orderId);
    }


    @GetMapping("/isBuyCourse/{courseId}/{memberId}")
    public boolean isBuyCourse(@PathVariable String courseId,@PathVariable String memberId){
        return orderService.isBuyCourse(courseId,memberId);
    }

}
